*****
*** Authors: Peter Eppinger (PE), Hong Ma (HM)
*** Purpose: Replicate all results in Online Appendix A
*** Stata version: 16.1
*** Date: February 20, 2024
***
***** 1. Header
***** 2. Online Appendix A: Chinese FDI policy
***
****************************************************************************************************************
***** 1. Header

cap log close
clear all
set linesize 255
log using "$results\3_FDI_liberalization_appendixA.log", replace

****************************************************************************************************************
***** 2. Online Appendix A: Chinese FDI policy

********************************************************
**** Figure A.1: Distribution of matching similarity score for 2002

use "$proprietary_data\policy_similarity02.dta", clear  // from \FDI_projectdata\Data_resubmission\policy_nlp\appendix-match-figure

histogram similarity02_ind, frac fcolor(blue*0.8) lcolor(black) lw(thin) bin(50) graphregion(color(white)) xlabel(0(0.1)1, format(%03.1f)) name("figA1", replace)

graph export "$results\FigureA1.eps", name("figA1") font("Times") replace
count if similarity02_ind<. 
sum similarity02_ind,d


********************************************************
**** Table A.3: Summary statistics for alternative FDI policy measures

use "$prepared_data\comb_data_analysis.dta", clear

* generate policy dummy variables
gen res=0 if year<2002 & policy97!=1 
replace res=1 if year<2002 & policy97==1
replace res=0 if year>=2002 & year<2005 & policy02!=1 
replace res=1 if year>=2002 & year<2005 & policy02==1
replace res=0 if year>=2005 & policy05!=1 
replace res=1 if year>=2005 & policy05==1
gen frd=0 if year<2002 & policy97!=0
replace frd=1 if year<2002 & policy97==0
replace frd=0 if year>=2002 & year<2005 & policy02!=0 
replace frd=1 if year>=2002 & year<2005 & policy02==0
replace frd=0 if year>=2005 & policy05!=0 
replace frd=1 if year>=2005 & policy05==0
gen enc=0 if year<2002 & policy97!=3
replace enc=1 if year<2002 & policy97==3
replace enc=0 if year>=2002 & year<2005 & policy02!=3 
replace enc=1 if year>=2002 & year<2005 & policy02==3
replace enc=0 if year>=2005 & policy05!=3 
replace enc=1 if year>=2005 & policy05==3

egen resfrd=rowtotal(res frd)
recode resfrd (2=1)

label var frd "Prohibited FDI (product)"
label var res "Restricted FDI (product)"
label var resfrd "Restricted or prohibited FDI (product)"
label var enc  "Encouraged FDI (product)"
label var frd_brandt "Prohibited FDI (Brandt et al., 2017)"
label var res_brandt "Restricted FDI (Brandt et al., 2017)"
label var resfrd_brandt "Restricted or prohibited FDI (Brandt et al., 2017)"
label var enc_sheng_yang  "Encouraged FDI (Sheng \& Yang, 2016)"
label var frd_sheng_yang "Prohibited FDI (Sheng \& Yang, 2016)"
label var res_sheng_yang "Restricted FDI (Sheng \& Yang, 2016)"
label var resfrd_sheng_yang "Restricted or prohibited FDI (Sheng \& Yang, 2016)"

sum res res_sheng_yang res_brandt  frd frd_brandt frd_sheng_yang   resfrd resfrd_brandt resfrd_sheng_yang  enc enc_sheng_yang
 
sutex  res res_sheng_yang res_brandt  frd frd_brandt frd_sheng_yang   resfrd resfrd_brandt resfrd_sheng_yang  enc enc_sheng_yang, file("$results\TableA3") replace minmax labels key(tab_sumpolicy) nocheck pl(p) title("Table A.3: Summary statistics for alternative FDI policy measures")

********************************************************
**** Table A.4: Correlations across alternative FDI policy measures

label var frd "Prohibited (product)"
label var res "Restricted (product)"
label var resfrd "Restricted or prohibited (product)"
label var enc  "Encouraged (product)"
label var frd_brandt "Prohibited (BVBWZ2017)"
label var res_brandt "Restricted (BVBWZ2017)"
label var resfrd_brandt "Restricted or prohibited (BVBWZ2017)"
label var enc_sheng_yang  "Encouraged (SY2016)"
label var frd_sheng_yang "Prohibited (SY2016)"
label var res_sheng_yang "Restricted (SY2016)"
label var resfrd_sheng_yang "Restricted or prohibited (SY2016)"

pwcorr res res_sheng_yang res_brandt  frd frd_brandt frd_sheng_yang   resfrd resfrd_brandt resfrd_sheng_yang  enc enc_sheng_yang

corrtex res res_sheng_yang res_brandt  frd frd_brandt frd_sheng_yang   resfrd resfrd_brandt resfrd_sheng_yang  enc enc_sheng_yang, file("$results\TableA4") replace case key(tab_corrpolicy) title("Table A.4: Correlations across alternative FDI policy measures")

** Numbers on overlap/correlation for liberalization with Brandt et al measure mentioned in Appendix A.2:

* code liberalized vs. still restricted industries by Brandt et al measure:
gen lib_vsres_brandt=liberalized_brandt
recode lib_vsres_brandt (2=.) (99=.)

* compare to product-level policy measure:
tab lib1_full01 lib_vsres_brandt if year==2001,m 
corr lib1_full01 lib_vsres_brandt if year==2001,m

********************************************************
**** Figure A.2: Cross-sectoral distribution of liberalized firms, 2001

label def cic2_lab 13 "13 Food Processing" 14 "14 Food Production" 15 "15 Beverages" 16 "16 Tobacco" 17 "17 Textiles" 18 "18 Garments" 19 "19 Leather/Fur/Feather" 20 "20 Timber" 21 "21 Furniture " 22 "22 Paper" 23 "23 Printing" 24 "24 Cultural/Educational/Sports" 25 "25 Petroleum Processing" 26 "26 Raw Chemicals" 27 "27 Pharmaceuticals" 28 "28 Chemical Fibers" 29 "29 Rubber" 30 "30 Plastics" 31 "31 Non-metallic Mineral Products" 32 "32 Ferrous Metals" 33 "33 Nonferrous Metals" 34 "34 Metal Products" 35 "35 Basic Machinery" 36 "36 Special Equipment" 37 "37 Transport Equipment" 39 "39 Electrical Machinery/Equipment" 40 "40 Electronics/Telecommunications" 41 "41 Instruments" 42 "42 Other manufacturing" 43 "43 Metal Recycling", modify
label val cic2 cic2_lab
tab cic2 lib1_full01

* Sheng/Yang liberalization by industry
* zero if restricted in 2001 and same product will not be liberalized in 2002
* - initially restricted:
gen lib1_sheng_yang=0 if year<=2001 & (res_sheng_yang==1 | frd_sheng_yang==1)
gen lib1_sheng_yang01=lib1_sheng_yang if year==2001
bys firm_id: egen lib1_sheng_yang2001=max(lib1_sheng_yang01)
* - initial industry code:
gen cic01=cic_code if year==2001
bys firm_id: egen cic2001=max(cic01)
replace lib1_sheng_yang=0 if year>=2002 & (res_sheng_yang==1 | frd_sheng_yang==1) & cic_code==cic2001 & lib1_sheng_yang2001==0 // only for those with unchanged industry codes
replace lib1_sheng_yang=1 if year>=2002 & (res_sheng_yang==0 & frd_sheng_yang==0) & cic_code==cic2001 & lib1_sheng_yang2001==0 // only for those with unchanged industry codes
bys cic_code: egen lib_vsres_sheng_yang=max(lib1_sheng_yang) 
drop lib1_sheng_yang lib1_sheng_yang01 lib1_sheng_yang2001 cic01 cic2001

* Figure A.2(a): Shares of liberalized firms among all firms by sector
preserve
	* reduce to 2001
	keep if year==2001
	* aggregate by industry
	collapse (count) count=res (sum) lib1_full01 lib_vsres_sheng_yang  lib_vsres_brandt, by(cic2)
	rename lib1_full01 lib_base
	rename lib_vsres_sheng_yang lib_shen 
	rename lib_vsres_brandt lib_brandt
	foreach x of varlist /*res frd enc jv maj anyres*/ lib_base lib_shen lib_brandt {
		replace `x'=`x'/count*100
	}
	drop count
	reshape long lib_, i(cic2) j(typ) string
	* CIC code 39 is missing; reduce by one to avoid gap:
	replace cic2=cic2-1 if cic2>=39 
	* shift by a few milimeters to improve visibility:
	gen ind2=cic2 if typ=="shen"
	replace ind2 = cic2-0.25 if typ=="base"
	replace ind2 = cic2+0.25 if typ=="brandt"
	label copy cic2_lab ind2_lab, replace
	label def ind2_lab 38 "39 Electrical Machinery/Equipment" 39 "40 Electronics/Telecommunications" 40 "41 Instruments " 41 "42 Other manufacturing", modify
	label val ind2 ind2_lab
	twoway (bar lib_ ind2 if typ=="shen" , barwidth(0.25) color(cranberry*0.75) fi(80)) (bar lib_ ind2 if typ=="base", barwidth(0.25) color(dknavy) fi(80)) (bar lib_ ind2 if typ=="brandt", barwidth(0.25) color(gold) fi(80)), xlabel(13/41,nogrid valuelabel noticks angle(270) labsize(vsmall)) graphregion(color(white)) legend(order(2 "Product-level" 1 "Sheng & Yang (2016)" 3 "Brandt et al. (2017)") row(1) size(small) bmargin(vsmall) region(margin(vsmall)) keygap(0.5) symysize(*0.8) symxsize(*0.3)) ytitle("Share of liberalized firms (in percent)", size(small)) xtitle("") ylabel(#9,grid labs(vsmall)) ysize(6) xsize(7) plotregion(margin(small)) graphregion(margin(small)) name("FigA2a", replace)
restore
graph export "$results\FigureA2a.eps", name("FigA2a") replace font("Times")

* Figure A.2 (b) Shares of liberalized firms among initially restricted firms by sector
preserve
	* reduce to 2001
	keep if year==2001
	* aggregate by industry
	collapse (mean) lib1_full01 lib_vsres_sheng_yang  lib_vsres_brandt, by(cic2)
	gen lib_base=lib1_full01*100
	gen lib_shen=lib_vsres_sheng_yang*100
	gen lib_brandt=lib_vsres_brandt*100
	reshape long lib_, i(cic2) j(typ) string
	* CIC code 39 is missing; reduce by one to avoid gap:
	replace cic2=cic2-1 if cic2>=39 
	* shift by a few milimeters to improve visibility:
	gen ind2=cic2 if typ=="shen"
	replace ind2 = cic2-0.25 if typ=="base"
	replace ind2 = cic2+0.25 if typ=="brandt"
	label copy cic2_lab ind2_lab, replace
	label def ind2_lab_short 38 "39" 39 "40" 40 "41" 41 "42", modify
	label val ind2 ind2_lab_short
	twoway (bar lib_ ind2 if typ=="shen" , barwidth(0.25) color(cranberry*0.75) fi(80)) (bar lib_ ind2 if typ=="base", barwidth(0.25) color(dknavy) fi(80)) (bar lib_ ind2 if typ=="brandt", barwidth(0.25) color(gold) fi(80)), xlabel(13/41,nogrid valuelabel noticks labsize(medsmall)) graphregion(color(white)) legend(off) ytitle("Share of liberalized in restricted firms (in percent)", size(medlarge)) xtitle("") ylabel(#5,grid labs(medsmall)) ysize(3.8) xsize(7)  name("FigA2b", replace)
restore
graph export "$results\FigureA2b.eps", name("FigA2b") replace font("Times")

********************************************************
**** Table A.5: Violations of the prohibited FDI policy across alternative measures

gen foreign_nonzero=0 if foreign_share==0
replace foreign_nonzero=1 if foreign_share>0 & foreign_share<.
gen foreign_owned=0 if foreign_share!=.
replace foreign_owned=1 if foreign_share>=0.25 	// Chinese legal threshold for FIE status

* overall
sum foreign_nonzero foreign_owned foreign_full foreign_share

* in prohibited industries by our new firm-level FDI policy classification:
sum foreign_nonzero foreign_owned foreign_full foreign_share if  frd==1
* in prohibited industries as classified by Brandt et al. FDI:
sum foreign_nonzero foreign_owned foreign_full foreign_share if  frd_brandt==1
* in prohibited industries as classified by Sheng/Yang FDI:
sum foreign_nonzero foreign_owned foreign_full foreign_share if  frd_sheng_yang==1

label var foreign_nonzero  "\textit{FO share} $>$ 0"
label var foreign_owned  "\textit{FO share} $\geq$ 25\%"
label var foreign_full  "\textit{Full foreign ownership}"
label var foreign_share "\textit{FO share}"

sutex  foreign_nonzero foreign_owned foreign_full foreign_share if  frd==1, file("$results\TableA5") replace  labels key(tab_sumviolations) nocheck pl(p)  title("Summary statistics of foreign ownership for firms with FDI classified as prohibited")
sutex  foreign_nonzero foreign_owned foreign_full foreign_share if  frd_brandt==1  , file("$results\TableA5") append labels key(tab_sumviolations) nocheck pl(p) title("Summary statistics of foreign ownership for firms with FDI classified as prohibited by Brandt et al.")
sutex  foreign_nonzero foreign_owned foreign_full foreign_share if  frd_sheng_yang==1  , file("$results\TableA5") append labels key(tab_sumviolations) nocheck pl(p) title("Summary statistics of foreign ownership for firms with FDI classified as prohibited by Sheng/Yang")
